package com.liujit.generator.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;

import java.sql.Connection;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description 数据库配置
 * @Author LiuJun
 * @Date 2020/8/13 4:14 下午
 */
@Data
@ConfigurationProperties(prefix = "datasource")
public class DataSourceConfig {

    private Map<String, String> url = new HashMap<>();

    private String driverName;

    private String userName;

    private String password;

    public Connection getConn(String projectName) {
        Connection conn = null;
        try {
            Class.forName(this.driverName);
            conn = DriverManager.getConnection(this.url.get(projectName), this.userName, this.password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
}
